package com.isoftstone.project.monitor.floor.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.isoftstone.project.monitor.floor.domain.MonitorFloor;
import com.isoftstone.project.monitor.floor.service.IMonitorFloorService;
import com.isoftstone.framework.controller.BaseController;
import com.isoftstone.framework.domain.Page;
import com.isoftstone.framework.domain.Tidings;
import com.isoftstone.common.utils.ExcelUtil;
import com.isoftstone.framework.domain.PageData;

/**
 * 地面监测Controller
 *
 * @author guoX
 * @date 2021-02-02
 */
@Controller
@RequestMapping("/monitor/floor")
public class MonitorFloorController extends BaseController {
    private String prefix = "monitor/floor";

    @Autowired
    private IMonitorFloorService monitorFloorService;

    @RequiresPermissions("monitor:floor:view")
    @GetMapping()
    public String floor() {
        return prefix + "/floor_list";
    }

    /**
     * 查询地面监测列表
     */
    @RequiresPermissions("monitor:floor:list")
    @PostMapping("/monitorFloorlistPage")
    @ResponseBody
    public Object getmonitorFloorlistPage(Page page) {
        PageData pd = this.getPageData();
        page.setPd(pd);
        List<MonitorFloor> list = monitorFloorService.getMonitorFloorlistPage(page);
        return Tidings.success(page.getTotalResult(), list);
    }


    /**
     * 导出地面监测列表
     */
    @RequiresPermissions("monitor:floor:export")
    @PostMapping("/exportMonitorFloor")
    @ResponseBody
    public Object exportMonitorFloor(Page page) {
        PageData pd = this.getPageData();
        page.setPd(pd);
        page.setEntityOrField(false);
        List<MonitorFloor> list = monitorFloorService.getMonitorFloorlistPage(page);
        ExcelUtil<MonitorFloor> util = new ExcelUtil<MonitorFloor>(MonitorFloor. class);
        return util.exportExcel(list, "floor");
    }

    /**
     * 新增地面监测
     */
    @GetMapping("/addMonitorFloor")
    public String addMonitorFloor() {
        return prefix + "/floor_add";
    }


    /**
     * 新增保存地面监测
     */
    @RequiresPermissions("monitor:floor:add")
    @PostMapping("/addMonitorFloor")
    @ResponseBody
    public Object insertMonitorFloor(MonitorFloor monitorFloor) {
        monitorFloorService.insertMonitorFloor(monitorFloor);
        return Tidings.success();

    }

    /**
     * 修改地面监测
     */
    @GetMapping("/toEditMonitorFloor")
    public String toEditMonitorFloor(String workDate, ModelMap mmap) {
        MonitorFloor monitorFloor =monitorFloorService.getMonitorFloorById(workDate);
        mmap.put("monitorFloor", monitorFloor);
        return prefix + "/floor_edit";
    }

    /**
     * 修改保存地面监测
     */
    @RequiresPermissions("monitor:floor:edit")
    @PostMapping("/updateMonitorFloor")
    @ResponseBody
    public Object updateMonitorFloor(MonitorFloor monitorFloor) {
        monitorFloorService.updateMonitorFloor(monitorFloor);
        return Tidings.success();
    }

    /**
     * 删除地面监测
     */
    @RequiresPermissions("monitor:floor:remove")
    @PostMapping("/deleteMonitorFloor")
    @ResponseBody
    public Object deleteMonitorFloor(String workDate) {
        monitorFloorService.deleteMonitorFloorByIds(workDate);
        return Tidings.success();
    }

}
